﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;
using System.Web.SessionState;

namespace SES.CMS
{
    public partial class ThongTin : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                load();
            }
        }

        public void initForm()
        {

        }

        public void initLabel()
        {

        }
        public void initUpdate()
        {
            txtDC.Visible = true;
            txtDT.Visible = true;
            txtEmail.Visible = true;
            txtHT.Visible = true;
            txtMobile.Visible = true;

            lbDC.Visible = false;
            lbEmail.Visible = false;
            lbHT.Visible = false;
            lbMobile.Visible = false;
            lbDT.Visible = false;
        }

        private void load()
        {
            if (Session["IDDN"] != null)
            {
                initForm();
                ClientLoginDO obj = new ClientLoginBL().Select(new ClientLoginDO { ClientLoginID = int.Parse(Session["IDDN"].ToString()) });


                lblDN.Text = obj.Username;
                lbHT.Text = obj.ClientName;
                lbDT.Text = obj.Phone;
                lbMobile.Text = obj.Mobile;
                lbEmail.Text = obj.Email;
                lbDC.Text = obj.Address;

                txtDC.Text = obj.Address;
                txtDT.Text = obj.Phone;
                txtEmail.Text = obj.Email;
                txtMobile.Text = obj.Mobile;
                txtHT.Text = obj.ClientName;
                Page.Title = "Thông tin cá nhân - " + obj.ClientName + " | Văn phòng phẩm Mỹ Đình";
            }
            else
            {
                Response.Redirect("/Default.aspx");
            }
        }

        public ClientLoginDO initObj()
        {
            ClientLoginDO obj = new ClientLoginDO();
            obj = new ClientLoginBL().Select(new ClientLoginDO { ClientLoginID = int.Parse(Session["IDDN"].ToString()) });
            return obj;
        }


        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            initUpdate();
            btnCapNhat.Visible = false;
            btnUpdate.Visible = true;
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            ClientLoginDO obj = initObj();
            //if (txtHT.Visible == true)
            obj.ClientName = txtHT.Text;
            //else if (txtDC.Visible == true)
            obj.Address = txtDC.Text;
            //else if (txtDT.Visible == true)
            obj.Mobile = txtDT.Text;
            //else if (txtEmail.Visible == true)
            obj.Email = txtEmail.Text;
            obj.Mobile = txtMobile.Text;

            new ClientLoginBL().Update(obj);
            Ultility.Alert("Cập nhật thành công!", Request.Url.ToString());
            btnUpdate.Visible = false;
            btnCapNhat.Visible = true;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Default.aspx");
        }


        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
        public cmsGioHangDO init()
        {
            cmsGioHangDO obj = new cmsGioHangDO();
            if (Session["ClientLoginID"] == null)
                obj.ClientLoginID = 0;
            else
                obj.ClientLoginID = int.Parse(Session["ClientLoginID"].ToString());
            obj.NgayDatHang = Convert.ToDateTime(DateTime.Now.ToString());
            obj.NgayGiaoHang = Convert.ToDateTime(DateTime.Now.ToString());
            obj.SoLuong = 1;
            obj.XuLy = false;
            return obj;
        }
    }
}
